﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using TS.DataAccess;
using TS.Entities;

namespace TS.Bussiness
{
    public class ConfigurationBussiness
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public int UpdateConfig(Configuration config)
        {
            ConfigurationDataAccess configDao = new ConfigurationDataAccess();
            try
            {
                return configDao.UpdateConfiguration(config);
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return -1;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public int UpdateClosed(Configuration config)
        {
            ConfigurationDataAccess configDao = new ConfigurationDataAccess();
            try
            {
                return configDao.UpdateClose(config);
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return -1;
        }

        public int UpdateViewCount()
        {
            var configDao = new ConfigurationDataAccess();
            try
            {
                return configDao.UpdateViewCount();
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return -1;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public Configuration GetConfig()
        {
            var userDao = new ConfigurationDataAccess();
            try
            {
                Configuration user = userDao.GetConfig();
                return user;
            }
            catch (SqlException exception)
            {
                Console.WriteLine(exception.ToString());
            }
            return null;
        }
    }
}
